package com.sptpc.learnspring;

import com.sptpc.learnspring.model.Category;
import com.sptpc.learnspring.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@Slf4j
@SpringBootApplication
public class LearnSpringApplication  implements ApplicationRunner {
    @Autowired
    private CategoryService categoryService;

    public static void main(String[] args) {
        SpringApplication.run(LearnSpringApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        Category category = categoryService.saveCategory("果汁");
//        log.info("创建一个新的分类：{}",category);

//        List<Category> categoryList = categoryService.findAll();
//        categoryList.forEach(c -> {
//            log.info("分类：{}",c);
//        });

//        Category category = categoryService.findOne("果%");
//        log.info("分类：{}",category);

        Category category = categoryService.update(24L,"鲜榨果汁");
        log.info("更新分类：{}",category);

        if (categoryService.delete(24L)) {
            log.info("删除成功");
        } else {
            log.error("删除失败");
        }
    }
}
